/******************************************************************************
 * The contents of this file are subject to the   JDI License  Version 1.0
 * ("License"); You may not use this file except in compliance with the License
 * Software distributed under the License is distributed on an  "AS IS"  basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
 * the specific language governing rights and limitations under the License.
 * The Initial Developer of the Original Code is 陈慧然. Portions created by 
 * 陈慧然 are Copyright 陈慧然.
 * All Rights Reserved.
 *
 *              Contact john_holen@163.com for licensing alternatives.
 *
 *****************************************************************************/


package org.peony.client.web.components.form;

import org.peony.client.web.components.WebComponents;
import org.peony.exceptions.RenderException;
import org.peony.standard.unvarying.client.ComponentsSize;
import org.peony.tools.StringUtil;

/**
 *  
 *
 *  @author     陈慧然
 *  @version    Id: InputText.java, v 0.000 2008-5-1 下午01:52:12 陈慧然 Exp
 */
public class InputText extends WebComponents{
	private Label label;
	private String value;
	private boolean isReadOnly = false;
	private boolean isDisabled = false;
	private int size = 0;
	private int maxLength = 0;
	@Override
	public String toStandardString() throws RenderException {
		if(StringUtil.isEmpty(getId()))
			throw new RenderException("input Text(A Component) Can NOT has no id!");
		StringBuffer sb = new StringBuffer();
		sb.append(getLabel()==null?empty:getLabel().toStandardString())
			.append("<input type=\"").append("text\"")
			.append(" id= \"").append(getId()).append("\"")
			.append(" name=\"").append(getId()).append("\"")
			.append(StringUtil.isNotEmpty(getUIClass())?" class=\"" + getUIClass()+"\"":empty)
			.append(isReadOnly()?" readonly=\"readonly\"":empty)
			.append(isDisabled()?" disabled=\"disabled\"":empty)
			.append(" size=\"").append(getSize()).append("\"");
		if(getMaxLength() > 0){
			sb.append(" maxLength=\"").append(getMaxLength()).append("\"");
		}
		sb.append(StringUtil.isEmpty(getValue())?empty:"value=\""+getValue()+"\"").append(" />");
		return sb.toString();
	}
	public Label getLabel() {
		return label;
	}
	public void setLabel(Label label) {
		this.label = label;
	}
	public String getValue() {
		return value;
	}
	public void setValue(String value) {
		this.value = value;
	}
	public boolean isReadOnly() {
		return isReadOnly;
	}
	public void setReadOnly(boolean isReadOnly) {
		this.isReadOnly = isReadOnly;
	}
	public boolean isDisabled() {
		return isDisabled;
	}
	public void setDisabled(boolean isDisabled) {
		this.isDisabled = isDisabled;
	}
	public int getSize() {
		if(size <= 0)
			return ComponentsSize.sizeForTextInput;
		return size;
	}
	public void setSize(int size) {
		this.size = size;
	}
	public int getMaxLength() {
		return maxLength;
	}
	public void setMaxLength(int maxLength) {
		this.maxLength = maxLength;
	}
}
